import axios from 'axios'

import { getToken } from './token'

// 创建axios实例
const service = axios.create({
  // API的BASE_URL
  baseURL: process.env.NODE_ENV === 'production' ? process.env.VUE_APP_BASE_API : '/',
  // 请求超时时间
  timeout: 60000
})

// request拦截器
service.interceptors.request.use(
  config => {
    if (!config.headers['Content-Type']) {
      config.headers['Content-Type'] = 'application/json'
    }

    // 再请求头添加加密的token验证
    config.headers['token'] = getToken()

    // config.headers['clientType'] = Settings.clientType

    return config
  },
  error => {
    Promise.reject(error)
  }
)

export default service
